|
RAIS
3.2
|
00001 00028 using System; 00029 using System.Data; 00030 using System.Configuration; 00031 using System.Collections; 00032 using System.Collections.Generic; 00033 using System.Web; 00034 using System.Web.Security; 00035 using System.Web.UI; 00036 using System.Web.UI.WebControls; 00037 using System.Web.UI.WebControls.WebParts; 00038 using System.Web.UI.HtmlControls; 00039 00040 using RAIS; 00041 using RAIS.Common.UserManagement; 00042 //using RAIS.ApplicationLogicLayer; 00043 00044 using DataRoles = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.DataRole>; 00045 using DataRoleAttributes = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.DataRoleAttribute>; 00046 using Regions = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.Region>; 00047 using Districts = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.District>; 00048 using Facilities = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.Facility>; 00049 00050 namespace RAIS.UI.SpecificMasks 00051 { 00055 public partial class EditDataRoles : System.Web.UI.Page 00056 { 00057 #region Event handlers 00058 protected void Page_PreLoad(object sender, EventArgs e) 00059 { 00060 RAIS.UI.Common.PageManagement.TrimTextBoxValues(this); 00061 } 00069 protected void Page_Load(object sender, EventArgs e) 00070 { 00071 this.Response.Redirect("EditDataRoles_New.aspx"); 00072 00073 if (this.CurrentUser == null) 00074 UI.Common.AccessManagement.SignOut(this); 00075 00076 if (!this.IsPostBack) 00077 { 00078 this.BTNdmdelete.Attributes.Add("onclick", string.Format("javascript: return confirm('{0}');", RAIS.Common.Messages.DELETE_QUESTION_DATA_ROLE.Replace("'", "\\'"))); 00079 UI.Common.UserManagement.InitializeDataRoles(this); 00080 } 00081 00082 this.InitializeControls(); 00083 this.EnableRemoveButton(); 00084 00085 this.LBLresult.Text = ""; 00086 00087 if (!this.IsPostBack) 00088 { 00089 this.LBLusername.Text = this.CurrentUser.Name; 00090 this.EditMode = false; 00091 00092 UI.Common.PageManagement.InitializePage(this, this.TreeView1); 00093 // this.LBTNmessagebox.Visible = !(this.CurrentUser.FunctionalRole.Type == FunctionRole.FunctionRoleType.Guest); 00094 } 00095 } 00096 protected void Page_Init(object sender, EventArgs e) 00097 { 00098 Common.PageManagement.SetScrolableListBox(this.LBdm, this, true); 00099 } 00106 protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) 00107 { 00108 UI.Common.UserManagement.ProcessTreeViewOnRedirect(this.TreeView1); 00109 } 00116 protected void LBTNlogout_Click(object sender, EventArgs e) 00117 { 00118 UI.Common.AccessManagement.SignOut(this); 00119 } 00120 00129 protected void DDLdmrolename_SelectedIndexChanged(object sender, EventArgs e) 00130 { 00131 UI.Common.UserManagement.InitializeDataRoleAttributesList(this.LBdm, this.SelectedRole); 00132 } 00133 00141 protected void BTNdmnewrole_Click(object sender, EventArgs e) 00142 { 00143 this.AddDataRole(); 00144 } 00145 00153 protected void BTNdmdelete_Click(object sender, EventArgs e) 00154 { 00155 if (this.ConfirmRoleDeletion()) 00156 { 00157 this.DeleteSelectedRole(); 00158 } 00159 } 00160 00168 protected void DDLdmregion_SelectedIndexChanged(object sender, EventArgs e) 00169 { 00170 this.DDLdmdistrict.Items.Clear(); 00171 this.DDLdmfacility.Items.Clear(); 00172 00173 UI.Common.UserManagement.InitializeDistrictsList( this.DDLdmdistrict, 00174 this.DDLdmregion.SelectedValue); 00175 00176 UI.Common.UserManagement.InitializeFacilitiesList( this.DDLdmfacility, 00177 this.DDLdmregion.SelectedValue, 00178 this.DDLdmdistrict.SelectedValue); 00179 } 00180 00188 protected void DDLdmdistrict_SelectedIndexChanged(object sender, EventArgs e) 00189 { 00190 this.DDLdmfacility.Items.Clear(); 00191 UI.Common.UserManagement.InitializeFacilitiesList( this.DDLdmfacility, 00192 this.DDLdmregion.SelectedValue, 00193 this.DDLdmdistrict.SelectedValue); 00194 } 00195 00203 protected void BTNdmadd_Click(object sender, EventArgs e) 00204 { 00205 this.AddDataRoleAttribute(); 00206 this.EnableRemoveButton(); 00207 this.EnableDisableControls(); 00208 } 00209 00217 protected void BTNdmremove_Click(object sender, EventArgs e) 00218 { 00219 this.RemoveDataRoleAttribute(); 00220 this.InitializeControls(); 00221 this.EnableRemoveButton(); 00222 this.EnableDisableControls(); 00223 } 00231 protected void BTNedit_Click(object sender, EventArgs e) 00232 { 00233 this.EditMode = true; 00234 this.EnableRemoveButton(); 00235 } 00243 protected void BTNsave_Click(object sender, EventArgs e) 00244 { 00245 this.SaveRole(); 00246 this.InitializeControls(); 00247 this.EnableRemoveButton(); 00248 } 00256 protected void BTNdiscard_Click(object sender, EventArgs e) 00257 { 00258 this.Session[RAIS.UI.Common.Constants.DATA_ROLES_TAG] = null; //for resetting 00259 this.InitializeControls(); 00260 this.EnableRemoveButton(); 00261 this.EditMode = false; 00262 } 00263 00270 protected void LBdm_SelectedIndexChanged(object sender, EventArgs e) 00271 { 00272 try 00273 { 00274 this.InitializeControls(); 00275 this.SetRegionSelection(this.SelectedRoleAttribute); 00276 this.SetDistrictSelection(this.SelectedRoleAttribute); 00277 this.SetFacilitySelection(this.SelectedRoleAttribute); 00278 } 00279 catch 00280 { 00281 } 00282 } 00283 #endregion 00284 #region Private helper methods 00285 00288 private void RemoveDataRoleAttribute() 00289 { 00290 DataRole selectedRole = this.SelectedRole; 00291 if (selectedRole != null) 00292 { 00293 DataRoleAttribute attribute = this.SelectedRoleAttribute; 00294 00295 string returnMessage = RAIS.Common.Messages.MODIFICATION_PRESS_SAVE; 00296 bool success = selectedRole.RemoveAttribute(attribute, ref returnMessage); 00297 // bool success = ApplicationLogicLayer.UserManagement.RemoveDataRoleAttribute(selectedRole, attribute, ref returnMessage); 00298 00299 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, 00300 returnMessage, 00301 success); 00302 } 00303 00304 00305 } 00309 private void AddDataRoleAttribute() 00310 { 00311 DataRole selectedRole = this.SelectedRole; 00312 if (selectedRole != null) 00313 { 00314 DataRoleAttribute dataRoleAttribute = new DataRoleAttribute(); 00315 dataRoleAttribute.Region = this.SelectedRegion; 00316 dataRoleAttribute.District = this.SelectedDistrict; 00317 dataRoleAttribute.Facility = this.SelectedFacility; 00318 00319 string returnMessage = RAIS.Common.Messages.MODIFICATION_PRESS_SAVE; 00320 bool bSuccess = this.ValidateNewDataRoleAttribute(dataRoleAttribute, ref returnMessage); 00321 if (bSuccess) 00322 { 00323 selectedRole.AddAttribute(dataRoleAttribute, ref returnMessage); 00324 // bSuccess = ApplicationLogicLayer.UserManagement.AddDataRoleAttribute(selectedRole, dataRoleAttribute, ref returnMessage); 00325 UI.Common.UserManagement.InitializeDataRoleAttributesList(this.LBdm, selectedRole); 00326 this.LBdm.SelectedValue = dataRoleAttribute.ToString(); 00327 } 00328 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, 00329 returnMessage, 00330 bSuccess); 00331 } 00332 } 00336 private void AddDataRole() 00337 { 00338 string validationMessage = RAIS.Common.Messages.MODIFICATION_PRESS_SAVE; 00339 bool bSuccess = this.ValidateNewDataRole(this.TXTnewrole.Text, ref validationMessage); 00340 if (bSuccess) 00341 { 00342 bSuccess = ApplicationLogicLayer.UserManagement.AddDataRole(this.TXTnewrole.Text, ref validationMessage); 00343 00344 this.Session[RAIS.UI.Common.Constants.DATA_ROLES_TAG] = null; //for resetting 00345 UI.Common.UserManagement.InitializeDataRolesList(this.DDLdmrolename); 00346 this.DDLdmrolename.SelectedValue = this.TXTnewrole.Text; 00347 UI.Common.UserManagement.InitializeDataRoleAttributesList(this.LBdm, this.SelectedRole); 00348 this.TXTnewrole.Text = ""; 00349 00350 } 00351 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage( this.LBLresult, 00352 validationMessage, 00353 bSuccess); 00354 } 00358 private void DeleteSelectedRole() 00359 { 00360 DataRole selectedRole = this.SelectedRole; 00361 00362 bool success = false; 00363 string returnMessage = RAIS.Common.Messages.MODIFICATION_PRESS_SAVE; 00364 if (selectedRole != null) 00365 { 00366 success = ApplicationLogicLayer.UserManagement.RemoveDataRole(selectedRole, ref returnMessage); 00367 if (success) 00368 { 00369 this.Session[RAIS.UI.Common.Constants.DATA_ROLES_TAG] = null; //for resetting 00370 UI.Common.UserManagement.InitializeDataRolesList(this.DDLdmrolename); 00371 this.DDLdmrolename.SelectedIndex = 0; 00372 } 00373 } 00374 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage( this.LBLresult, 00375 returnMessage, 00376 success); 00377 } 00382 private bool SaveRole() 00383 { 00384 string returnMessage = ""; 00385 bool success = true; 00386 00387 if (!this.Modified) 00388 { 00389 returnMessage = RAIS.Common.Messages.DATA_ROLE_NO_MODIFICATION; 00390 success = false; 00391 } 00392 else 00393 { 00394 success = ApplicationLogicLayer.UserManagement.SaveDataRole(this.SelectedRole, ref returnMessage); 00395 if (success) 00396 this.EditMode = false; 00397 } 00398 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, 00399 returnMessage, 00400 success); 00401 return success; 00402 } 00411 bool ValidateNewDataRole(string dataRoleName, ref string returnMessage) 00412 { 00413 DataRoles dataRoles = (DataRoles)this.Session[UI.Common.Constants.DATA_ROLES_TAG]; 00414 if (dataRoles.ContainsKey(dataRoleName)) 00415 { 00416 returnMessage = RAIS.Common.Messages.DATA_ROLE_EXISTS; 00417 return false; 00418 } 00419 else 00420 if (dataRoleName.Length == 0) 00421 { 00422 returnMessage = RAIS.Common.Messages.NAME_IS_EMTPY; 00423 return false; 00424 } 00425 else 00426 00427 return true; 00428 } 00437 bool ValidateNewDataRoleAttribute(DataRoleAttribute newDataRoleAttributeName, ref string returnMessage) 00438 { 00439 DataRole dataRole = this.SelectedRole; 00440 if (dataRole == null) 00441 { 00442 returnMessage = RAIS.Common.Messages.DATA_ROLE_DOES_NOT_EXIST; 00443 return false; 00444 } 00445 else 00446 { 00447 return dataRole.ValidateNewAttribute(newDataRoleAttributeName, ref returnMessage); 00448 } 00449 } 00454 private bool ConfirmRoleDeletion() 00455 { 00456 return true; 00457 } 00461 private void EnableRemoveButton() 00462 { 00463 this.BTNdmremove.Enabled = this.LBdm.Items.Count > 0 && 00464 this.SelectedRole.Attributes.ContainsKey(this.LBdm.SelectedValue) && 00465 this.EditMode; 00466 } 00470 private void InitializeControls() 00471 { 00472 UI.Common.UserManagement.InitializeDataRolesList(this.DDLdmrolename); 00473 UI.Common.UserManagement.InitializeRegionsList(this.DDLdmregion, this.SelectedRole); 00474 00475 UI.Common.UserManagement.InitializeDistrictsList(this.DDLdmdistrict, 00476 this.DDLdmregion.SelectedValue); 00477 00478 UI.Common.UserManagement.InitializeFacilitiesList(this.DDLdmfacility, 00479 this.DDLdmregion.SelectedValue, 00480 this.DDLdmdistrict.SelectedValue); 00481 00482 UI.Common.UserManagement.InitializeDataRoleAttributesList(this.LBdm, 00483 this.SelectedRole); 00484 00485 } 00489 private void EnableDisableControls() 00490 { 00491 this.LBdm.Enabled = this.EditMode; 00492 00493 this.DDLdmregion.Enabled = this.EditMode; 00494 this.DDLdmdistrict.Enabled = this.EditMode; 00495 this.DDLdmfacility.Enabled = this.EditMode; 00496 00497 this.BTNdmadd.Enabled = this.EditMode; 00498 this.BTNdmremove.Enabled = this.EditMode; 00499 00500 this.BTNedit.Enabled = !this.EditMode; 00501 this.BTNsave.Enabled = this.Modified; 00502 this.BTNdiscard.Enabled = this.EditMode; ; 00503 00504 this.DDLdmrolename.Enabled = !this.EditMode; 00505 this.TXTnewrole.Enabled = !this.EditMode; 00506 this.BTNdmnewrole.Enabled = !this.EditMode; 00507 this.BTNdmdelete.Enabled = !this.EditMode; 00508 00509 UI.Common.UserManagement.EnableCommonControls(this, !this.EditMode); 00510 this.LBLadmin.ForeColor = RAIS.UI.Common.Constants.COLOR_OF_MENU_BAR_TEXT_HIGHLIGHT; 00511 } 00512 #endregion 00513 00518 private void SetRegionSelection(DataRoleAttribute roleAttribute) 00519 { 00520 if (roleAttribute != null) 00521 { 00522 this.DDLdmregion.SelectedValue = roleAttribute.Region.Name; 00523 } 00524 } 00530 private void SetDistrictSelection(DataRoleAttribute roleAttribute) 00531 { 00532 if (roleAttribute != null) 00533 { 00534 this.DDLdmdistrict.SelectedValue = roleAttribute.District.Name; 00535 } 00536 } 00542 private void SetFacilitySelection(DataRoleAttribute roleAttribute) 00543 { 00544 if (roleAttribute != null) 00545 { 00546 this.DDLdmfacility.SelectedValue = roleAttribute.Facility.Name; 00547 } 00548 } 00549 #region Private properties 00550 00553 private DataRole SelectedRole 00554 { 00555 get 00556 { 00557 DataRoles dataRoles = (DataRoles)this.Session[UI.Common.Constants.DATA_ROLES_TAG]; 00558 if (dataRoles != null) 00559 return dataRoles[this.DDLdmrolename.SelectedValue]; 00560 else 00561 return null; 00562 } 00563 } 00567 private Region SelectedRegion 00568 { 00569 get 00570 { 00571 Regions regions = (Regions)this.Session[RAIS.UI.Common.Constants.REGIONS_TAG]; 00572 if (regions != null) 00573 return regions[this.DDLdmregion.SelectedValue]; 00574 else 00575 return null; 00576 } 00577 } 00581 private District SelectedDistrict 00582 { 00583 get 00584 { 00585 Districts districts = ApplicationLogicLayer.UserManagement.GetDistrictsByRegion(this.SelectedRegion); 00586 if (districts != null) 00587 return districts[this.DDLdmdistrict.SelectedValue]; 00588 else 00589 return null; 00590 } 00591 } 00595 private Facility SelectedFacility 00596 { 00597 get 00598 { 00599 Region selectedRegion = this.SelectedRegion; 00600 District selectedDistrict = this.SelectedDistrict; 00601 Facilities facilities = ApplicationLogicLayer.UserManagement.GetFacilitiesByRegionAndDistrict(selectedRegion, selectedDistrict); 00602 if (facilities != null) 00603 return facilities[this.DDLdmfacility.SelectedValue]; 00604 else 00605 return null; 00606 } 00607 } 00611 private DataRoleAttribute SelectedRoleAttribute 00612 { 00613 get 00614 { 00615 DataRole selectedRole = this.SelectedRole; 00616 if (selectedRole != null && selectedRole.Attributes.ContainsKey(this.LBdm.SelectedValue)) 00617 return selectedRole.Attributes[this.LBdm.SelectedValue]; 00618 else 00619 return null; 00620 } 00621 } 00625 bool EditMode 00626 { 00627 get 00628 { 00629 if(this.Session[RAIS.UI.Common.Constants.DATA_ROLE_EDIT_MODE_TAG] != null ) 00630 return (bool)this.Session[RAIS.UI.Common.Constants.DATA_ROLE_EDIT_MODE_TAG]; 00631 else 00632 return false; 00633 } 00634 set 00635 { 00636 this.Session[RAIS.UI.Common.Constants.DATA_ROLE_EDIT_MODE_TAG] = value; 00637 this.EnableDisableControls(); 00638 } 00639 } 00643 bool Modified 00644 { 00645 get 00646 { 00647 if (this.SelectedRole != null) 00648 return this.SelectedRole.Modified; 00649 else 00650 return false; 00651 } 00652 set 00653 { 00654 if (!value) 00655 { 00656 this.SelectedRole.Modified = false; 00657 this.Session[RAIS.UI.Common.Constants.DATA_ROLES_TAG] = null; 00658 this.EnableDisableControls(); 00659 } 00660 } 00661 } 00665 protected UserData CurrentUser 00666 { 00667 get { return (UserData)this.Session[UI.Common.Constants.CURRENT_USER_TAG]; } 00668 } 00669 #endregion Properties 00670 } 00671 }